#pragma once
#include "epoll.h"
#include "channel.h"
#include<memory>
#include<iostream>

class EventLoop
{
private:
    std::shared_ptr<Epoll> ep;
    bool quit = false;
public:
    EventLoop(std::shared_ptr<Epoll> _ep);
    ~EventLoop();
    void loop();
    void updateChannel(Channel*);
};

EventLoop::EventLoop(std::shared_ptr<Epoll> _ep):ep(_ep)
{
}

EventLoop::~EventLoop()
{
}

void EventLoop::loop(){
    while(!quit){
        std::vector<std::unique_ptr<Channel>> chs = ep->poll();
        for(auto it = chs.begin(); it != chs.end(); ++it){
            (*it)->handleEvent();
        }
    }
}
